package cn.dnuihyy406.dnuifood_16110100406.controller.homefragment;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import java.util.ArrayList;
import java.util.List;

import cn.dnuihyy406.dnuifood_16110100406.R;
import cn.dnuihyy406.dnuifood_16110100406.bean.ShopBean;
import cn.dnuihyy406.dnuifood_16110100406.listener.OnRetrofitListener;
import cn.dnuihyy406.dnuifood_16110100406.model.ShopModel;

public class HomeFragment extends Fragment implements OnRetrofitListener<List<ShopBean>> {
    private RecyclerView recyclerView;
    private ShopAdapter adapter;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container
            , @Nullable Bundle savedInstanceState) {

        return inflater.inflate(R.layout.home_fragment,container,false);
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        initViews();
        initData();

        recyclerView.setItemAnimator(new DefaultItemAnimator());
        recyclerView.setAdapter(new ShopAdapter(getActivity(),getData()));
    }

    @Override
    public void onSuccess(List<ShopBean> object, int flag) {
        adapter=new ShopAdapter(getActivity(),object);
        recyclerView.setAdapter(adapter);

    }

    @Override
    public void onFailure(String msg) {

    }
    void initViews(){
        recyclerView = getActivity().findViewById(R.id.RecylerView);
        recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
    }
    void initData(){
        ShopModel shopModel = new ShopModel();
        shopModel.getAllShops(this);
    }
    void initEvents(){

    }
    private List<ShopBean> getData() {
        List<ShopBean> list = new ArrayList() ;
        return list;
    }
}

